package me.stephenj.experiment2.mapper;

import me.stephenj.experiment2.model.Person;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Title PersonsMapper.java
 * @Description PersonsMapper接口类
 * @author 张润天
 * @Time 2020/4/21 12:09
 * @version v0.01
 */

@Component
public interface PersonsMapper {
    /**
     * @Title Method
     * @Description 获取所有联系人
     */
    @Select("SELECT `ID`, `FirstName`, `LastName` FROM `Person`")
    List<Person> getAll();

    /**
     * @Title Method
     * @Description 获取一个联系人的详细信息
     */
    @Select("SELECT * FROM `Person` WHERE ID=#{ID}")
    Person getOne(int ID);

    /**
     * @Title Method
     * @Description 添加联系人
     */
    @Insert("INSERT INTO `person` (FirstName, LastName, PhoneNrsID, MailsID, Pics, CompanyID) VALUES (#{FirstName}, #{LastName}, #{PhoneNrsID}, #{MailsID}, #{Pics}, #{CompanyID})")
    int insert(Person person);

    /**
     * @Title Method
     * @Description 修改联系人信息
     */
    @Update("UPDATE `Person` SET FirstName=#{FirstName}, LastName=#{LastName}, Pics=#{Pics} WHERE ID=#{ID}")
    int update(Person person);

    /**
     * @Title Method
     * @Description 删除联系人
     */
    @Delete("DELETE FROM `Person` WHERE ID=#{ID}")
    int delete(int ID);
}
